home *** CD-ROM | disk | FTP | other *** search
- Path: news.clinet.fi!usenet
- From: tkassila@pcuf.fi (Tuomas Kassila)
- Newsgroups: comp.lang.c++
- Subject: istrstream var(char*) and var >> number?
- Date: 19 Feb 1996 14:04:11 GMT
- Organization: Clinet, Espoo, Finland.
- Message-ID: <4ga00r$mln@news.clinet.fi>
- NNTP-Posting-Host: pcuf.fi
-
- /*
- Can somebody answer, why out-commented lines not work with
- B4.53/ANSI C++ instead of line marked with #2 version?
- And is there an another (way with istrstream-variable), wich works?
- Here is my little program, which reads stdin. An input is like:
-
- some row 1
- 233 Messageheader
- <end of file>
-
- and output is:
-
- some row 1
- review 233
- <end of file>
-
- If I run the program with version 1 lines (version 2-line is then
- comment line), output will be like:
-
- some row 1
- 233 Messageheader
- <end of file>
- */
-
- #include <iostream.h>
- #include <strstrea.h>
- #define LINELEN 100
-
- main()
- {
- unsigned long msgnumber = 0;
- char line[LINELEN+1];
- // istrstream str(line); // #1 version
-
- *line = '\0';
- while (cin.getline(line, LINELEN))
- {
- // see my question above:
- istrstream str(line); // this #2 version works = ok!
- if (str >> msgnumber )
- cout << "review " << msgnumber << endl;
- else
- cout << line << endl;
- //str.seekg(0L, ios::beg); // #1 version
- }
- return 0;
- } // end of program (and the message)
- // --------------------------------------------------------------
- // Thanks, Tuomas
-